package com.zdb.n1.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.OptBoolean;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity
@Table(name = "fitness_goals")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class FitnessGoal {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    @JsonIgnoreProperties({"password", "roles"})
    private User user;

    @NotBlank
    private String title; // 目标标题

    private String description; // 描述

    @NotNull
    @Enumerated(EnumType.STRING)
    private GoalType type;

    private String targetValue; // 目标值，如"减重5kg"中的"5"

    private String unit; // 单位，如"kg"、"次"等

    @NotNull
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime startDate;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime targetDate; // 目标完成日期

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime completedDate; // 实际完成日期

    private Double progress; // 进度，0-100

    @Enumerated(EnumType.STRING)
    private GoalStatus status = GoalStatus.ACTIVE;

    // 周期性目标的频率设置
    private Integer frequency; // 频率数值，如"每周3次"中的"3"
    
    @Enumerated(EnumType.STRING)
    private FrequencyUnit frequencyUnit; // 频率单位，如"每周"、"每月"



    public enum GoalType {
        WEIGHT_LOSS("减重目标"),
        EXERCISE_FREQUENCY("运动频率"),
        DISTANCE("距离目标"),
        STRENGTH("力量目标"),
        ENDURANCE("耐力目标"),
        CUSTOM("自定义");

        private final String displayName;

        GoalType(String displayName) {
            this.displayName = displayName;
        }

        public String getDisplayName() {
            return displayName;
        }
    }

    public enum GoalStatus {
        ACTIVE("进行中"),
        COMPLETED("已完成"),
        FAILED("未达成"),
        ABANDONED("已放弃");

        private final String displayName;

        GoalStatus(String displayName) {
            this.displayName = displayName;
        }

        public String getDisplayName() {
            return displayName;
        }
    }

    public enum FrequencyUnit {
        DAY("每天"),
        WEEK("每周"),
        MONTH("每月");

        private final String displayName;

        FrequencyUnit(String displayName) {
            this.displayName = displayName;
        }

        public String getDisplayName() {
            return displayName;
        }
    }
} 